package com.hrm.service.lxy;

import com.hrm.dao.lxy.EmpMapper;
import com.hrm.dao.lxy.FaceMapper;
import com.hrm.entity.Dept;
import com.hrm.entity.Employee;
import com.hrm.entity.Job;
import com.hrm.entity.User;
import com.hrm.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 李雪阳
 * @version 1.0
 * @date 2020/8/1  15:25
 */
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    EmpMapper empMapper;
    @Autowired
    FaceMapper faceMapper;

    /**
     * 添加人脸信息
     *
     * @param faceToken
     * @param id
     * @return int
     */
    @Override
    public int updateFaceToken(String faceToken, Integer id, Integer tip) {
        if (tip == 1) {
            return faceMapper.updateFaceTokenForUser(faceToken, id);
        } else {
            return faceMapper.updateFaceTokenForEmp(faceToken, id);
        }
    }

    /**
     * 获取全部员工列表
     *
     * @param name
     * @return List<Employee>
     */
    @Override
    public List<Employee> getEmpList(String name, PageInfo<Employee> page) {
        return empMapper.selectEmpList(name, page);
    }

    /**
     * 获取单个员工信息
     *
     * @param uid
     * @return Employee
     */
    @Override
    public Employee getEmpById(Integer uid) {
        return empMapper.selectEmpById(uid);
    }

    /**
     * 查找部门列表
     *
     * @return List<Dept>
     */
    @Override
    public List<Dept> getDeptList() {
        return empMapper.selectDeptList();
    }

    /**
     * 查找职位列表
     *
     * @return List<Job>
     */
    @Override
    public List<Job> getJobList() {
        return empMapper.selectJobList();
    }

    /**
     * 增加员工
     *
     * @param emp
     * @return int
     */
    @Override
    public int addEmp(Employee emp) {
        return empMapper.addEmp(emp);
    }

    /**
     * 修改员工信息
     *
     * @param emp
     * @return int
     */
    @Override
    public int updateEmpById(Employee emp) {
        return empMapper.modifyEmpById(emp);
    }

    /**
     * 通过员工id删除一个员工
     *
     * @param id
     * @return int
     */
    @Override
    public int deleteEmpById(Integer id) {
        return empMapper.deleteEmpById(id);
    }

    /**
     * 获取全部员工个数
     *
     * @return Integer
     */
    @Override
    public int getEmpNum(String name) {
        return empMapper.selectEmpNum(name);
    }

    /**
     * 根据用户id查询user
     *
     * @param id
     * @return User
     */
    @Override
    public User getUserById(Integer id) {

        return faceMapper.selectUserById(id);
    }
}
